<template>
  <div class="test-finance">
    <h2>库存查询API测试</h2>
    
    <div class="test-section">
      <h3>1. 测试获取选项数据</h3>
      <el-button @click="testGetOptions">测试获取选项</el-button>
      <div v-if="optionsResult" class="result">
        <pre>{{ JSON.stringify(optionsResult, null, 2) }}</pre>
      </div>
    </div>
    
    <div class="test-section">
      <h3>2. 测试获取库存数据</h3>
      <el-button @click="testGetStockData">测试获取库存数据</el-button>
      <div v-if="stockResult" class="result">
        <pre>{{ JSON.stringify(stockResult, null, 2) }}</pre>
      </div>
    </div>
    
    <div class="test-section">
      <h3>3. 测试获取库存分布数据</h3>
      <el-button @click="testGetDistributionData">测试获取库存分布</el-button>
      <div v-if="distributionResult" class="result">
        <pre>{{ JSON.stringify(distributionResult, null, 2) }}</pre>
      </div>
    </div>
    
    <div class="test-section">
      <h3>4. 测试获取出入库流水数据</h3>
      <el-button @click="testGetFlowData">测试获取出入库流水</el-button>
      <div v-if="flowResult" class="result">
        <pre>{{ JSON.stringify(flowResult, null, 2) }}</pre>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { FinanceRed } from '@/http/axiosHelper'
import { ElMessage } from 'element-plus'

const optionsResult = ref(null)
const stockResult = ref(null)
const distributionResult = ref(null)
const flowResult = ref(null)

const testGetOptions = async () => {
  try {
    const response = await FinanceRed.get('/api/ledgar/GetCategories')
    optionsResult.value = response.data
    ElMessage.success('获取选项数据成功')
  } catch (error) {
    console.error('获取选项数据失败:', error)
    ElMessage.error('获取选项数据失败: ' + error.message)
  }
}

const testGetStockData = async () => {
  try {
    const params = {
      PageIndex: 1,
      PageSize: 10
    }
    const response = await FinanceRed.get('/api/ledgar/GetLedgar', { params })
    stockResult.value = response.data
    ElMessage.success('获取库存数据成功')
  } catch (error) {
    console.error('获取库存数据失败:', error)
    ElMessage.error('获取库存数据失败: ' + error.message)
  }
}

const testGetDistributionData = async () => {
  try {
    const params = {
      Product_Id: '1', // 测试产品ID
      Product_Name: '测试产品',
      Product_Number: 'TEST001'
    }
    const response = await FinanceRed.get('/api/ledgar/GetDistribution', { params })
    distributionResult.value = response.data
    ElMessage.success('获取库存分布数据成功')
  } catch (error) {
    console.error('获取库存分布数据失败:', error)
    ElMessage.error('获取库存分布数据失败: ' + error.message)
  }
}

const testGetFlowData = async () => {
  try {
    const params = {
      Product_Id: '1', // 测试产品ID
      Product_Name: '测试产品',
      Product_Number: 'TEST001',
      PageIndex: 1,
      PageSize: 10
    }
    const response = await FinanceRed.get('/api/ledgar/GetWarehouse_InOrOut', { params })
    flowResult.value = response.data
    ElMessage.success('获取出入库流水数据成功')
  } catch (error) {
    console.error('获取出入库流水数据失败:', error)
    ElMessage.error('获取出入库流水数据失败: ' + error.message)
  }
}
</script>

<style scoped>
.test-finance {
  padding: 20px;
}

.test-section {
  margin-bottom: 30px;
  padding: 20px;
  border: 1px solid #ddd;
  border-radius: 8px;
}

.result {
  margin-top: 10px;
  padding: 10px;
  background-color: #f5f5f5;
  border-radius: 4px;
  max-height: 300px;
  overflow-y: auto;
}

.result pre {
  margin: 0;
  white-space: pre-wrap;
  word-wrap: break-word;
}
</style> 